﻿@model DoeLibsMVC.Models.RenewExpireDateModel

@*
    this page will be render a modal and doesn't contain a layout. it will be included on the title details page directly
*@

<div class="modal fade" id="renewExpireDateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            @using (Html.BeginForm("RenewExpireDate", "User", FormMethod.Post, new { id = "renewExpireDateForm" }))
            {

                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span class="closeButton" aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">renew expire date request</h4>
                </div>
                <div class="modal-body">
                    <table class="formTable">
                        <tbody>
                            <tr>
                                <td>
                                    @Html.LabelFor(model => model.AcceptorId)
                                </td>
                                <td>
                                    <div>
                                        @Html.DropDownListFor(model => model.AcceptorId, Model.StaffMembers, new { @class = "registerDropDownList" })
                                        @Html.ValidationMessageFor(model => model.AcceptorId)
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">send request</button>
                </div>
            }
        </div>
    </div>
</div>

<script type="text/javascript">
    $("#renewExpireDateForm").submit(function () {
        console.log(getFormData($('#renewExpireDateForm')));

        $.ajax({
            url: '/api/User/?renewExpireDateRequest',
            type: 'POST',
            beforeSend: function (xhr) {
                xhr.setRequestHeader("Authorization", getAuthorizationHeader('@User.UserId', ''));
            },
            data: getFormData($('#renewExpireDateForm'))
        }).done(function (data) {
            console.log("success");
            setHttpMessage("Request sent", true);

            location.reload();
        }).fail(function (data) {
            clearAllErrorFields('renewExpireDateForm');

            console.log(data);
            if (data.status == 400) {
                console.log("bad request");

                addErrorsToFields("model.", data.responseJSON);
            } else {
                console.log("status: " + data.status);
                //servererror, etc.
                setHttpMessageDynamic("Technical problems. Please try again", false);
            }
        });

    return false;
    });
</script>

